<?php

require_once '../include/common.inc.php';
require_once '../include/upfile.class.php';

if (!checkAdmin()) {
    header("LOCATION:index.php");
    exit;
}

$menu_index = 1;
$page_title = 'JANSEN';
$guide_message = 'Product | Delete Products';
$ppp = 50;
$page_show = '';

getMyParam('sub1_x');
getMyParam('sub2_x');
getMyParam('pid_ary');



if (($sub1_x != "" || $sub2_x != "") && !empty($pid_ary)) 
{

    if ($sub1_x != "")
	 {
        foreach ($pid_ary as $v) {
            $sql_1 = "UPDATE `product` SET `delete_flag` = 0 WHERE `id` = '" . $v . "'";
			 
            //$db->query($sql_1);
        }
    }
	 elseif ($sub2_x != "")
	 {
        foreach ($pid_ary as $v) {
            $sql_1 = "DELETE FROM `product` WHERE `id` = '" . $v . "'";
            $sql_2 = "DELETE FROM `product_inventory` WHERE `product_id` = '" . $v . "'";
            $sql_3 = "DELETE FROM `product_category` WHERE `product_id` = '" . $v . "'";
			echo $sql_1."in".$sub2_x."t".$sub1_x﻿;
           //$db->query($sql_1) && $db->query($sql_2) && $db->query($sql_3);
        }
    }

    //echo "<pre>"; print_r($db->sql_ary);exit;
    //header("LOCATION:p_confirm_delete.php");
}


//

$sql = "SELECT `product_id` FROM product_category WHERE `seq`>0 GROUP BY `product_id`";
$query = $db->query($sql);
while($rs = $db->fetch_array($query)) 
{
    $product_id_ary[] = $rs['product_id'];
}


$product_id_str = implode(",", $product_id_ary);
	
$sql = "SELECT `id` FROM product WHERE `id` NOT IN (" . $product_id_str . ")";
$query = $db->query($sql);
$sql_all_num = $db->num_rows($query);

// *** page code start ***
getMyParam('page');
$page = empty($page) || !ispage($page) ? 1 : $page;
$start_limit = ($page - 1) * $ppp;
if($start_limit > $sql_all_num) {
    $start_limit = 0;
    $page = 1;
}
$page_url = 'p_confirm_delete.php?';
// *** page code end ***

$sql = "SELECT `id`, `name`, `code`, `pic`, `small_pic`, `price_1`, `price_2`, `price_3`, `hidden_flag`, `new_flag`, `comment` FROM product WHERE `id` NOT IN (" . $product_id_str . ") ORDER BY `code` DESC LIMIT $start_limit, $ppp";
$query = $db->query($sql);
while($rs = $db->fetch_array($query)) {
    $out_ary[] = $rs;
}

$page_show = getPageStr($sql_all_num, $page, $ppp, $page_url);

$debug = 1;
debuginfo();

include_once(JANSEN_ROOT . 'admin/menu_list.php');
require_once PrintEot('a_header');
require_once PrintEot('a_p_confirm_delete');
require_once PrintEot('a_footer');

?>